package com.ubing.boot.notesforjava.test.obs;

import com.obs.services.ObsClient;

import java.io.*;

/**
 * @ClassName : test_obs
 * @Description : test_obs
 * @Author : Xxxxx
 * @Date: 2023-03-29 17:22
 */
public class test_obs {
    public static void main(String[] args) throws IOException {
        String endPoint = "obs.cn-north-4.myhuaweicloud.com";
        String ak = "XK9N5OQZAZW3W6KX2XTV";
        String sk = "XqIwZnGsWxvz41HjdWkG7GkPnALTe6DFuI43Plcx";
// 创建ObsClient实例
        ObsClient obsClient = new ObsClient(ak, sk, endPoint);
        File file = new File("E:\\GitHub\\notesforjava\\src\\main\\resources\\static\\avatar\\1640997204506312704微信图片.jpg");
//init array with file length
        byte[] bytesArray = new byte[(int) file.length()];

        FileInputStream fis = new FileInputStream(file);
        fis.read(bytesArray); //read file into bytes[]
        fis.close();
// 使用访问OBS
        obsClient.putObject("ubing-bucket", "微信图片.jpg", new ByteArrayInputStream(bytesArray));
// 关闭obsClient，全局使用一个ObsClient客户端的情况下，不建议主动关闭ObsClient客户端
        obsClient.close();
    }
}
